class Solution:
    def maximumSumQueries(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:
        # 合并列表，并降序排序
        ret = []
        tmp = (sorted([(nums1[i], nums2[i]) for i in range(len(nums1))], key=lambda x: sum(x), reverse=True))
        qmap = {}
        for i in queries:
            if str(i) not in qmap:
                curr_max = -1
                for j in tmp:
                    if j[0] >= i[0] and j[1] >= i[1]:
                        curr_max = sum(j)
                        break
                qmap[str(i)] = curr_max
                ret.append(curr_max)
            else:
                ret.append(qmap[str(i)])
        return ret
